<template>
    <div>
        <h1>康复理疗列表</h1>
        <a href="Addfu">添加康复理疗</a>
        <br>
        <a href="https://localhost:7235/api/KangFu/DC">导出康复理疗表</a>
        <br>
        <a href="Showfood">跳转到食谱列表</a>
        <br>
        康复名称<input type="text" v-model="paeg.kangName">
        <input type="button" value="查" @click="Show" >
        <table class="table">
            <thead>
                <tr>
                    <td><input type="checkbox" v-model="quan" @change="all"></td>
                    <td>康复名称</td>
                    <td>佣金</td>
                    <td>服务人数</td>
                    <td>服务时长</td>
                    <td>状态</td>
                    <td>操作</td>
                </tr>
            </thead>
            <tbody>
                <tr v-for="m in data">
                    <td><input type="checkbox" :value="m.kangId"  v-model="idlist" @change="noall" ></td>
                    <td>{{m.kangName}}</td>
                    <td>{{ m.kangPrice }}</td>
                    <td>{{ m.kangNum }}</td>
                    <td>{{ m.kangDate }}</td>
                    <td>{{m.kangStart?"启用":"禁用"}}</td>
                    <td><input type="button" value="逻辑删除" @click="dele" ></td>
                </tr>
            </tbody>
        </table>
        <input type="button" value="批量修改状态" @click="updat" >
        <br>
        <input type="button" value="首页" @click="fen(1)" >
        <input type="button" value="上一页" @click="fen(2)" >
        <input type="button" value="下一页" @click="fen(3)" >
        <input type="button" value="尾页" @click="fen(4)" >
        一共{{prcounts.count}}条,一共{{prcounts.prcount}}页，当前第{{paeg.pageindex}}页，每页{{paeg.pagesize}}条
        <select v-model="paeg.pagesize" @change="mei">
            <option>2</option>
            <option>3</option>
            <option>5</option>
        </select>
        <input type="text" v-model="paeg.pageindex">
        <input type="button" value="跳转" @click="zhuan">
    </div>
</template>

<script setup lang="ts">
import {onActivated, onMounted, ref} from 'vue';
import axios from 'axios';
const idlist=ref([0]);
const quan=ref(false);
//全选
const all=()=>{
    if(quan.value)
    {
        data.value.forEach(x=>{
            idlist.value.push(x.kangId);
        })
    }
    else
    {
        idlist.value=[];
    }
}
//反选
const noall=()=>{
    if(idlist.value.length==data.value.length)
    {
        quan.value=true;
    }
    else{
        quan.value=false;
    }
}
//逻辑删除
const dele=(kangId:any)=>{
    if(!confirm("确实逻辑删除吗？"))
{
    return;
}
    var ids=idlist.value.toString();
    axios.get("https://localhost:7235/api/KangFu/LJdele?idstring="+ids).then(res=>{
        if(res.data>0)
    {
        alert("逻辑删除成功！");
        Show();
    }
    else{
        alert("逻辑删除失败！");
    }
    })
}
//批量修改状态
const updat=(kangId:any)=>{
    if(!confirm("确实批量修改状态吗？"))
{
    return;
}
    var ids=idlist.value.toString();
    axios.get("https://localhost:7235/api/KangFu/Plupda?idstring="+ids).then(res=>{
        if(res.data>0)
    {
        alert("批量修改状态成功！");
        Show();
    }
    else{
        alert("批量修改状态失败！");
    }
    })
}
//分页
const fen=(e:any)=>{
    if(e==1)
    {
        paeg.value.pageindex=1;
        Show();
    }
    if(e==2)
    {
        if(paeg.value.pageindex>1)
        {
            paeg.value.pageindex-=1;
            Show();
        }
        }
    if(e==3)
    {
        if(paeg.value.pageindex<prcounts.value.prcount)
        {
            paeg.value.pageindex+=1;
            Show();
        }
    }
    if(e==4)
    {
        paeg.value.pageindex=paeg.value.pagesize;
        Show();
    }
}
const paeg=ref({
    kangName:"",
    pageindex:1,
    pagesize:2
})
const prcounts=ref({
    count:0,
    prcount:0
})
const mei=()=>{
    Show();
}
const zhuan=()=>{
    Show();
}
onMounted(()=>{
    Show();
})
const data=ref([{
        "kangId": 0,
        "code": "",
        "kangName": "",
        "kangPrice": "",
        "kangNum": 0,
        "kangDate": 0,
        "kangStart": false,
        "deleId": 0
}])
const Show=()=>{
    axios.get("https://localhost:7235/api/KangFu/Show",{params:paeg.value}).then(res=>{
        data.value=res.data.data;
        prcounts.value.count=res.data.count;
        prcounts.value.prcount=Math.ceil(res.data.count/paeg.value.pagesize)
    })
}
</script>

<style scoped>

</style>